<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-08-01 17:06
 *
 * Version: 2.0
 */

namespace App\Modules\Employee\Transformers;


use League\Fractal\TransformerAbstract;

class GetBarberRoyaltyTransformer extends TransformerAbstract
{
	private $list;
	private $baseSalary;
	private $storePayment;
	public function __construct($list,$baseSalary=0,$storePayment=null)
	{
		$this->list = $list;
		$this->baseSalary = $baseSalary;
		$this->storePayment = $storePayment;
	}

	public function transform()
	{
		$storePayment = $this->storePayment;
		$newList['items'] = $this->list->isEmpty() ? [] : array_map(function ($v) use($storePayment){
			return [
				'service_id'        => isset($v['store_service']) ? $v['store_service']['id'] : 0,
				'service'           => isset($v['store_service']) ? $v['store_service']['name'] : '烫发',
				'royalty'           => $v['royalty'],
				'status'            => $v['status'],
				'assistant_royalty' => $v['assistant_royalty'],
				'member_card'       => isset($storePayment->member_card) ? $storePayment->member_card : 100,
				'group_buy'			=> isset($storePayment->group_buy) ? $storePayment->group_buy : 100
			];
		}, $this->list->toArray());
		$newList['base_salary'] = $this->baseSalary;
		return $newList;
	}
}